#include<iostream>
#include<cstring>
using namespace std;
struct Student{
    char name[20];
    int mark;
};
int main(){
    int n,temp,i,j;
    cin>>n;
    Student s[n],temp1;
    char tname[20];    
    for(i=0;i<n;i++){
        cin>>s[i].name>>s[i].mark;
	}    
    for(i=0;i<n-1;i++){
      for(j=i+1;j<n;j++){
        if(s[i].mark<s[j].mark){
	        /*temp=s[i].mark;
	        s[i].mark=s[j].mark;
	        s[j].mark=temp;
	        strcpy(tname,s[i].name);
	        strcpy(s[i].name,s[j].name);
	        strcpy(s[j].name,tname);
	        swap(s[i],s[j]);*/
	        temp1=s[j];
	        s[j]=s[i];
	        s[i]=temp1;
        }
      }
    }    
    for(i=0;i<n;i++){
        cout<<s[i].name<<" "<<s[i].mark<<endl;}
    return 0;
}
